package com.wonghiu.consumer.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.wonghiu.api.HelloService;
import com.wonghiu.api.vo.Hello;
import com.wonghiu.framework.service.annotation.HRpcReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author wonghiu
 * @Date 2021/8/9 21:19
 * @Version 1.0.1
 */
@Controller
@RequestMapping("/hello")
public class HelloController {
    @HRpcReference
    private HelloService helloServiceHRpc;

    @Autowired
    @Qualifier("helloServiceLocal")
    private HelloService helloServiceLocal;

    @Reference(check = false)
    private HelloService helloServiceDubbo;

    @GetMapping("/checkRpc")
    @ResponseBody
    public String helloRPC(){
        System.out.println("controller:"+Thread.currentThread().getId());
        String hello = helloServiceHRpc.hello(new Hello("111", "Rpc"));
//        System.out.println(hello);
        return hello;
    }
    @GetMapping("/checkLocal")
    @ResponseBody
    public String helloLocal(){
        String hello = helloServiceLocal.hello(new Hello("222", "Local"));
//        System.out.println(hello);
        return hello;
    }

    @GetMapping("/checkDubbo")
    @ResponseBody
    public String helloDubbo(){
        String hello = helloServiceDubbo.hello(new Hello("333", "Dubbo"));
//        System.out.println(hello);
        return hello;
    }
}
